#!/user/bin/even Python3
# -*- coding:utf-8 -*-
# GuiTest.py
# 
# author:zhaohexin
# time：2020/5/18 21:44
import subprocess

import PySimpleGUI as sg

# Create some widgets
layout = [[sg.Text("What's your name?"), sg.InputText()],
          [sg.Button('OK'), sg.Button('Cancel')],
          [sg.Multiline('开始创建配置文件！', key='_Multiline_', size=(48, 7), autoscroll=True)],
          [sg.Button('刷新', key='Search')]
          ]

print = sg.Print

layout2 = [[sg.Multiline('开始创建配置文件！', key='_Multiline_', size=(48, 7), autoscroll=True)]]
# Create the Window
window = sg.Window('Hello PySimpleGUI', layout)
win2_active = False
# Create the event loop
while True:
    event, values = window.read()
    if event in (None, 'Cancel'):
        # User closed the Window or hit the Cancel button
        break

    if not win2_active and event == 'OK':
        s = subprocess.Popen("ping baidu.com -t", bufsize=0, stdout=subprocess.PIPE, universal_newlines=True)
        win2_active = True
        window2 = sg.Window('Window 2', layout2)

    if win2_active:
        events2, values2 = window2.Read(timeout=100)
        while True:
            nextline = s.stdout.readline()
           print(nextline.strip())

        if events2 is None or events2 == 'Exit':
            win2_active = False
            window2.close()

window.close()
